<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>添加用户</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui/css/layui.css">
    <link rel="stylesheet" href="../css/scroll-bar.css">
    <link rel="stylesheet" href="../css/sub-page.css">
    <link rel="stylesheet" href="../css/font.css">
</head>

<body>
    <div class="ok-body">
        <!--面包屑导航区域-->
        <div class="ok-body-breadcrumb">
            <span class="layui-breadcrumb">
                <a><cite>首页</cite></a>
                <a><cite>系统管理</cite></a>
                <a><cite>安全设置</cite></a>
            </span>
        </div>
        <!--form表单-->
        <form class="layui-form layui-form-pane ok-form">
            <div class="layui-form-item">
                <label class="layui-form-label">新的密码</label>
                <div class="layui-input-block">
                    <input type="password" name="password" placeholder="请输入密码" autocomplete="off" class="layui-input"
                        lay-verify="required">
                </div>

                <label class="layui-form-label">确认密码</label>
                <div class="layui-input-block">
                    <input type="password" name="confirm_password" placeholder="请输入密码" autocomplete="off" class="layui-input"
                        lay-verify="required">
                </div>


            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="add">立即提交</button>
                </div>
            </div>
        </form>
    </div>
    <!--js逻辑-->
    <script src="../lib/layui/layui.js"></script>
    <script src="../js/md5.js" type="text/javascript"></script>

    <script>
        layui.use(['element', 'form', 'jquery'], function () {
            var form = layui.form;
            var $ = layui.jquery;
            form.on('submit(add)', function (data) {
                console.log(data.field);
                data.field.password = hex_md5(data.field.password);
                console.log(data.field);

                // layer.msg("添加成功！", {
                //     icon: 6,
                //     time: 1000,
                //     anim: 4
                // }, function () {
                //     parent.layer.close(parent.layer.getFrameIndex(window.name));
                // });
                $.ajax({
                    url: '/users/resetpassword',
                    method: 'post',
                    data: data.field,
                    dataType: 'JSON',
                    success: function (res) {
                        if (res.code == 1) {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));
                            parent.window.location = "/login";
                        } else {
                            layer.msg('密码修改失败');
                        }
                    },
                    error: function (data) {}
                })

                return false;
            });
        })
    </script>
</body>

</html>